package com.milink.gateway.config;


import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Data
@PropertySource("classpath:ftpserver.properties")
@Configuration
public class FtpConfig implements WebMvcConfigurer {
    @Value("${ftpserver.user.admin.username}")
    private String username;

    @Value("${ftpserver.user.admin.userpassword}")
    private String userpassword;

    @Value("${ftpserver.user.admin.port}")
    private int port;

    @Value("${ftpserver.user.admin.homedirectory}")
    private String homedirectory;


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //可以通过os来判断
        String os = System.getProperty("os.name");
        //linux设置
        // registry.addResourceHandler("/ftp/**").addResourceLocations("file:/home/pic/");
        //windows设置
        //第一个方法设置访问路径前缀，第二个方法设置资源路径，既可以指定项目classpath路径，也可以指定其它非项目路径
        registry.addResourceHandler("/ftp/**").addResourceLocations("file:D:\\");
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }
}